package spring.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class Encryption {
	public static String getEncryptStr(String plaintext){
		String encryptStr = "Encrypt failed";
		try {
			MessageDigest md = MessageDigest.getInstance("sha-1");
			md.update(plaintext.getBytes("UTF-8"));
			byte [] bEncypt = md.digest();
			BASE64Encoder base64 = new BASE64Encoder();
			encryptStr = base64.encode(bEncypt);
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return encryptStr;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return encryptStr;
		}
		return encryptStr;
	}
}
